package com.hhj.sharding.sphere.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hhj.sharding.sphere.demo.model.OrderParamVO;
import com.hhj.sharding.sphere.demo.model.entity.Order;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author HHJ
 * @since 2024-05-20
 */
public interface OrderMapper extends BaseMapper<Order> {


    @Select("<script>" +
            " SELECT RE.* from t_order RE " +
            " where RE.is_deleted = 0 " +

            " <if test=\"req.id != null \"> " +
            " AND RE.id = #{req.id}" +
            " </if> " +

            " <if test=\"req.userId != null \"> " +
            " AND RE.user_id = #{req.userId}" +
            " </if> " +

            " <if test=\"req.orderId != null \"> " +
            " AND RE.order_id = #{req.orderId}" +
            " </if> " +

            " <if test=\"req.orderItemId != null \"> " +
            " AND RE.order_item_id = #{req.orderItemId}" +
            " </if> " +

            " <if test=\"req.testSnowflake != null \"> " +
            " AND RE.test_snowflake = #{req.testSnowflake}" +
            " </if> " +

            " <if test=\"req.startTime != null and req.endTime != null\"> " +
            " AND RE.create_time BETWEEN #{req.startTime} AND #{req.endTime} " +
            " </if> " +

            " <if test=\"req.snowCode != null and req.snowCode != '' and req.snowCode != '0' \"> " +
            " AND RE.snow_code = #{req.snowCode}" +
            " </if> " +

            " order by RE.create_time DESC,RE.id DESC" +

            "</script>")
    List<Order> findList(@Param("page") Page page, @Param("req") OrderParamVO req);
}
